#include "btform.h"
#include "ui_btform.h"

#include<QMouseEvent>
#include<QPropertyAnimation>


BTForm::BTForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BTForm)
{
    ui->setupUi(this);

    //先把lienBox隐藏，达到默认和点击时才显示的效果
    ui->lineBox->hide();

    //设置lien1动画效果
    line1Animal = new QPropertyAnimation(ui->line1,"geometry",this);
    line1Animal->setKeyValueAt(0,QRect(1,26,2,0));//设置关键帧
    line1Animal->setKeyValueAt(0.5,QRect(1,8,2,18));
    line1Animal->setKeyValueAt(1,QRect(1,26,2,0));
    line1Animal->setDuration(1500);//动画持续时间
    line1Animal->setLoopCount(-1);//循环次数，-1为无限循环
    line1Animal->start();

    //设置line2动画效果
    line2Animal = new QPropertyAnimation(ui->line2,"geometry",this);
    line2Animal->setKeyValueAt(0,QRect(9,26,2,0));//设置关键帧
    line2Animal->setKeyValueAt(0.5,QRect(9,8,2,18));
    line2Animal->setKeyValueAt(1,QRect(9,26,2,0));
    line2Animal->setDuration(1600);//动画持续时间
    line2Animal->setLoopCount(-1);//循环次数，-1为无限循环
    line2Animal->start();

    //设置line3动画效果
    line3Animal = new QPropertyAnimation(ui->line3,"geometry",this);
    line3Animal->setKeyValueAt(0,QRect(17,26,2,0));
    line3Animal->setKeyValueAt(0.5,QRect(17,8,2,18));
    line3Animal->setKeyValueAt(1,QRect(17,26,2,0));
    line3Animal->setDuration(1700);
    line3Animal->setLoopCount(-1);
    line3Animal->start();

    //设置line4动画效果
    line4Animal = new QPropertyAnimation(ui->line4,"geometry",this);
    line4Animal->setKeyValueAt(0,QRect(25,26,2,0));
    line4Animal->setKeyValueAt(0.5,QRect(25,8,2,18));
    line4Animal->setKeyValueAt(1,QRect(25,26,2,0));
    line4Animal->setDuration(1800);
    line4Animal->setLoopCount(-1);
    line4Animal->start();
}

BTForm::~BTForm()
{
    delete ui;
}

void BTForm::setIconAndText(const QString &icon, const QString &text,int pageId)
{
    //设置图标和文本
    ui->btIcon->setPixmap(QPixmap(icon));
    ui->btText->setText(text);

    //初始化pageId
    this->pageId = pageId;

}

int BTForm::getPageId() const
{
    return pageId;
}

void BTForm::clearbackground()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
}

void BTForm::showAnimal()
{
    ui->lineBox->show();
}

void BTForm::hideAnimal()
{
    ui->lineBox->hide();
}


void BTForm::mousePressEvent(QMouseEvent *event)
{
    //需要改变btStyle的背景颜色
    if((event->button() == Qt::LeftButton) | (event->button() == Qt::RightButton))
    {
       ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154)}QLabel{font-family:微软雅黑}");

    }

    //需要切换bodyRight中的page层叠页面
    emit btClicked(pageId);//发送信号


}
